#******************************************************************************
#******************************************************************************

# import libraries

import numpy as np

from dataclasses import dataclass, field, InitVar

#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

# fluid database
@dataclass
class FluidDatabase:
    """A class for databases of fluid properties enabling easy interpolation."""
    fluid_GAS = 'g'
    fluid_LIQUID = 'l'
    fluid_SOLID = 's'
    key_PRESSURE = 'p'
    key_TEMPERATURE = 't'
    key_DATA = 'd'
    
    fluid: str
    
    # fluid properties are nested dicts:
    # the first dict has 'phase' keys: fluid_GAS, fluid_LIQUID and fluid_SOLID
    # the second dict has other keys: key_PRESSURE, key_TEMPERATURE and key_DATA
    
    mass_density: dict = field(init=False)
    specific_heat: dict = field(init=False)
    dynamic_viscosity: dict = field(init=False)
    kinematic_viscosity: dict = field(init=False)
    thermal_conductivity: dict = field(init=False)
    thermal_diffusivity: dict = field(init=False)
    prandtl_number: dict = field(init=False)
    coefficient_expansion: dict = field(init=False) # no phase distinction   
    #surface_tension: dict = field(init=False)       # no phase distinction
    #heat_vaporisation: dict = field(init=False)     # no phase distinction
    
    source: InitVar[str] = None
    phase: InitVar[str] = None
    
    #**************************************************************************
    
    # def read_old(self, filename):
    
    #     #**********************************************************************
        
    #     # the CSV file should be organised as follows:
    #     # 1st row: labels
    #     # 2nd and subsequent rows: data
    #     # 1st column: temperature (in Kelvins)
    #     # 2nd column: pressure (in bar)
    #     # 3rd column: specific volume (in 1E-3 x m3/Kg), liquid state
    #     # 4th column: specific volume (in m3/Kg), gaseous state
    #     # 5th column: heat of vaporisation (in kJ per kg)
    #     # 6th column: dynamic viscosity (in 1E-6 x N s / m2), liquid
    #     # 7th column: dynamic viscosity (in 1E-6 x N s / m2), gaseous
    #     # 8th column: thermal conductivity (in 1E-3 x W/mK), liquid
    #     # 9th column: thermal conductivity (in 1E-3 x W/mK), gaseous
    #     # 10th column: prandtl number, fluid
    #     # 11th column: prandtl number, gaseous
    #     # 12th column: surface tension (in 1E-3 x N/m), gaseous
    #     # 13th column: expansion coefficient (in 1E-6 x K-1)
    #     # 14th column: temperature (in Kelvins)
        
    #     names = {0:'T_K',
    #              1:'p_bar',
    #              2:'sv_f_1E3_m3_Kg',
    #              3:'sv_g_m3_Kg',
    #              4:'hvap_kJ_kg',
    #              5:'cp_f_kJ_KgK',
    #              6:'cp_g_kJ_KgK',
    #              7:'dynvi_f_1E6_Ns_m2',
    #              8:'dynvi_g_1E6_Ns_m2',
    #              9:'k_f_1E3_W_mK',
    #              10:'k_g_1E3_W_mK',
    #              11:'Pr_f',
    #              12:'Pr_g',
    #              13:'SurfTens_1E3_N_m',
    #              14:'beta_1E6_1_K',
    #              15:'T_v2_K'}
                 
    #     # names = ['T_K',
    #     #          'p_bar',
    #     #          'sv_f_1E3_m3_Kg',
    #     #          'sv_g_m3_Kg',
    #     #          'hvap_kJ_kg',
    #     #          'cp_f_kJ_KgK',
    #     #          'cp_g_kJ_KgK',
    #     #          'dynvi_f_1E6_Ns_m2',
    #     #          'dynvi_g_1E6_Ns_m2',
    #     #          'k_f_1E3_W_mK',
    #     #          'k_g_1E3_W_mK',
    #     #          'Pr_f',
    #     #          'Pr_g',
    #     #          'SurfTens_1E3_N_m',
    #     #          'beta_1E6_1_K',
    #     #          'T_v2_K']

    #     #**********************************************************************
        
    #     # file specifications
        
    #     number_header_lines = 0 # the first line is for the labels/names
        
    #     number_footer_lines = 0 # no lines after the data
        
    #     file_dtypes = (np.float64,   # 'T_K'
    #                    np.float64,   # 'p_bar'
    #                    np.float64,   # 'sv_f_1E3_m3_Kg'
    #                    np.float64,   # 'sv_g_m3_Kg'
    #                    np.float64,   # 'hvap_kJ_kg'
    #                    np.float64,   # 'cp_f_kJ_KgK'
    #                    np.float64,   # 'cp_g_kJ_KgK'
    #                    np.float64,   # 'dynvi_f_1E6_Ns_m2'
    #                    np.float64,   # 'dynvi_g_1E6_Ns_m2'
    #                    np.float64,   # 'k_f_1E3_W_mK'
    #                    np.float64,   # 'k_g_1E3_W_mK'
    #                    np.float64,   # 'Pr_f'
    #                    np.float64,   # 'Pr_g'
    #                    np.float64,   # 'SurfTens_1E3_N_m'
    #                    np.float64,   # 'beta_1E6_1_K'
    #                    np.float64)   # 'T_v2_K'

    #     #**********************************************************************
        
    #     # convert units
        
    #     # 00: 'T_K',
    #     # 01: 'p_bar',
    #     # 02: 'sv_f_1E3_m3_Kg',
    #     # 03: 'sv_g_m3_Kg',
    #     # 04: 'hvap_kJ_kg',
    #     # 05: 'cp_f_kJ_KgK',
    #     # 06: 'cp_g_kJ_KgK',
    #     # 07: 'dynvi_f_1E6_Ns_m2',
    #     # 08: 'dynvi_g_1E6_Ns_m2',
    #     # 09: 'k_f_1E3_W_mK',
    #     # 10: 'k_g_1E3_W_mK',
    #     # 11: 'Pr_f',
    #     # 12: 'Pr_g',
    #     # 13: 'SurfTens_1E3_N_m',
    #     # 14: 'beta_1E6_1_K',
    #     # 15: 'T_v2_K'
        
    #     bar_2_Pa = 100000
        
    #     unit_converter = {
    #         1: lambda s: bar_2_Pa*np.float64(s),
    #         2: lambda s: 1/(np.float64(s)*1E-3),
    #         3: lambda s: 1/np.float64(s),
    #         5: lambda s: np.float64(s)*1E3,
    #         6: lambda s: np.float64(s)*1E3,
    #         7: lambda s: np.float64(s)*1E-6,
    #         8: lambda s: np.float64(s)*1E-6,
    #         9: lambda s: np.float64(s)*1E-3,
    #         10: lambda s: np.float64(s)*1E-3,
    #         13: lambda s: np.float64(s)*1E-3,
    #         15: lambda s: np.float64(s)*1E-6}

    #     #**********************************************************************
        
    #     # read the file
        
    #     # npdata = np.genfromtxt(
    #     #     filename, 
    #     #     dtype=file_dtypes,
    #     #     names=True,
    #     #     skip_header=number_header_lines,
    #     #     skip_footer=number_footer_lines,
    #     #     delimiter=',')
            
    #     npdata = np.genfromtxt(
    #         filename, 
    #         dtype=file_dtypes,
    #         names=True,
    #         skip_header=number_header_lines,
    #         skip_footer=number_footer_lines,
    #         delimiter=',',
    #         converters=unit_converter)

    #     #**********************************************************************
    
    #     # output:
        
    #     # specific_volume: dict
    #     # mass_density: dict
    #     # specific_heat: dict
    #     # dynamic_viscosity: dict 
    #     # thermal_conductivity: dict 
    #     # prandtl_number: dict 
    #     # coefficient_expansion: dict
        
    #     # fluid properties are nested dicts:
    #     # the first dict has 'phase' keys: fluid_GAS, fluid_LIQUID and fluid_SOLID
    #     # the second dict has other keys: key_PRESSURE, key_TEMPERATURE and key_DATAz
        
    #     # mass density, gas
        
    #     index_TEMPERATURE = 0
    #     index_PRESSURE = 1
    #     index_DATA = 3
        
    #     mass_density_gas = {
    #         self.key_PRESSURE: npdata[names[index_PRESSURE]],
    #         self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
    #         self.key_DATA: npdata[names[index_DATA]]}
        
    #     # mass density, liquid
        
    #     index_TEMPERATURE = 0
    #     index_PRESSURE = 1
    #     index_DATA = 2
        
    #     mass_density_liquid = {
    #         self.key_PRESSURE: npdata[names[index_PRESSURE]],
    #         self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
    #         self.key_DATA: npdata[names[index_DATA]]}
        
    #     # specific heat, gas
        
    #     index_TEMPERATURE = 0
    #     index_PRESSURE = 1
    #     index_DATA = 6
        
    #     specific_heat_gas = {
    #         self.key_PRESSURE: npdata[names[index_PRESSURE]],
    #         self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
    #         self.key_DATA: npdata[names[index_DATA]]}
        
    #     # specific heat, liquid
        
    #     index_TEMPERATURE = 0
    #     index_PRESSURE = 1
    #     index_DATA = 5
        
    #     specific_heat_liquid = {
    #         self.key_PRESSURE: npdata[names[index_PRESSURE]],
    #         self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
    #         self.key_DATA: npdata[names[index_DATA]]}
        
    #     # dynamic viscosity, gas
        
    #     index_TEMPERATURE = 0
    #     index_PRESSURE = 1
    #     index_DATA = 8
        
    #     dynamic_viscosity_gas = {
    #         self.key_PRESSURE: npdata[names[index_PRESSURE]],
    #         self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
    #         self.key_DATA: npdata[names[index_DATA]]}
        
    #     # dynamic viscosity, liquid
        
    #     index_TEMPERATURE = 0
    #     index_PRESSURE = 1
    #     index_DATA = 7
        
    #     dynamic_viscosity_liquid = {
    #         self.key_PRESSURE: npdata[names[index_PRESSURE]],
    #         self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
    #         self.key_DATA: npdata[names[index_DATA]]}
        
    #     # thermal conductivity, gas
        
    #     index_TEMPERATURE = 0
    #     index_PRESSURE = 1
    #     index_DATA = 10
        
    #     thermal_conductivity_gas = {
    #         self.key_PRESSURE: npdata[names[index_PRESSURE]],
    #         self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
    #         self.key_DATA: npdata[names[index_DATA]]}
        
    #     # thermal conductivity, liquid
        
    #     index_TEMPERATURE = 0
    #     index_PRESSURE = 1
    #     index_DATA = 9
        
    #     thermal_conductivity_liquid = {
    #         self.key_PRESSURE: npdata[names[index_PRESSURE]],
    #         self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
    #         self.key_DATA: npdata[names[index_DATA]]}
        
    #     # prandtl number, gas
        
    #     index_TEMPERATURE = 0
    #     index_PRESSURE = 1
    #     index_DATA = 12
        
    #     prandtl_number_gas = {
    #         self.key_PRESSURE: npdata[names[index_PRESSURE]],
    #         self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
    #         self.key_DATA: npdata[names[index_DATA]]}
        
    #     # prandtl number, liquid
        
    #     index_TEMPERATURE = 0
    #     index_PRESSURE = 1
    #     index_DATA = 11
        
    #     prandtl_number_liquid = {
    #         self.key_PRESSURE: npdata[names[index_PRESSURE]],
    #         self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
    #         self.key_DATA: npdata[names[index_DATA]]}
        
    #     # coefficient of expansion, liquid
        
    #     index_TEMPERATURE = 0
    #     index_PRESSURE = 1
    #     index_DATA = 14
        
    #     coefficient_expansion_liquid = {
    #         self.key_PRESSURE: npdata[names[index_PRESSURE]],
    #         self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
    #         self.key_DATA: npdata[names[index_DATA]]}
        
    #     # surface tension, gas
        
    #     index_TEMPERATURE = 0
    #     index_PRESSURE = 1
    #     index_DATA = 13
        
    #     surface_tension_liquid = {
    #         self.key_PRESSURE: npdata[names[index_PRESSURE]],
    #         self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
    #         self.key_DATA: npdata[names[index_DATA]]}
        
    #     # heat of vaporisation, gas
        
    #     index_TEMPERATURE = 0
    #     index_PRESSURE = 1
    #     index_DATA = 4
        
    #     heat_vaporisation_liquid = {
    #         self.key_PRESSURE: npdata[names[index_PRESSURE]],
    #         self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
    #         self.key_DATA: npdata[names[index_DATA]]}
        
    #     #**********************************************************************
        
    #     # for each property, add the pressure, temperature and data dicts
        
    #     mass_density = {self.fluid_GAS: mass_density_gas,
    #                     self.fluid_LIQUID: mass_density_liquid}
        
    #     specific_heat = {self.fluid_GAS: specific_heat_gas,
    #                      self.fluid_LIQUID: specific_heat_liquid}
        
    #     dynamic_viscosity = {self.fluid_GAS: dynamic_viscosity_gas,
    #                          self.fluid_LIQUID: dynamic_viscosity_liquid}
        
    #     thermal_conductivity = {self.fluid_GAS: thermal_conductivity_gas,
    #                             self.fluid_LIQUID: thermal_conductivity_liquid}
        
    #     prandtl_number = {self.fluid_GAS: prandtl_number_gas,
    #                       self.fluid_LIQUID: prandtl_number_liquid}
        
    #     # liquid only or independent
        
    #     coefficient_expansion = {
    #         self.fluid_LIQUID: coefficient_expansion_liquid}
                                 
    #     surface_tension = {
    #         self.fluid_LIQUID: surface_tension_liquid}
        
    #     heat_vaporisation = {
    #         self.fluid_LIQUID: heat_vaporisation_liquid}
    
    #     #**********************************************************************

    #     # return 
        
    #     return (
    #         mass_density, 
    #         specific_heat,
    #         dynamic_viscosity,
    #         thermal_conductivity,
    #         prandtl_number,
    #         coefficient_expansion,
    #         surface_tension,
    #         heat_vaporisation
    #         )
    
    #     #**********************************************************************

    #**************************************************************************
    #**************************************************************************
    
    def read(self, filename, phase):
    
        #**********************************************************************
        
        # the CSV file should be organised as follows:
        # 1st row: labels
        # 2nd and subsequent rows: data
        # 1st column: temperature (in Kelvins)
        # 2nd column: pressure (in bar)
        # 3rd column: mass density (in Kg/m3)
        # 4th column: specific heat (in J/KgK)
        # 5th column: dynamic viscosity (in N s / m2)
        # 6th column: kinematic viscosity (in m2/s)
        # 7th column: thermal conductivity (in W/mK)
        # 8th column: thermal diffusivity (in m2/s)
        # 9th column: prandtl number
        # 10th column: expansion coefficient (in 1/K)
        
        names = {0:'T_K',
                  1:'p_bar',
                  2:'rho_kg_m3',
                  3:'cp_J_Kg_K',
                  4:'dyn_vis_N_s_m2',
                  5:'kin_vis_m2_s',
                  6:'k_W_m_K',
                  7:'alpha_m2_s',
                  8:'Pr',
                  9:'beta'}

        #**********************************************************************
        
        # file specifications
        
        number_header_lines = 0 # the first line is for the labels/names
        
        number_footer_lines = 0 # no lines after the data
        
        file_dtypes = (np.float64,   # 0: 'T_K'
                        np.float64,   # 1: 'p_bar'
                        np.float64,   # 2: 'rho_kg_m3'
                        np.float64,   # 3: 'cp_J_Kg_K'
                        np.float64,   # 4: 'dyn_vis_N_s_m2'
                        np.float64,   # 5: 'kin_vis_m2_s'
                        np.float64,   # 6: 'k_W_m_K'
                        np.float64,   # 7: 'alpha_m2_s'
                        np.float64,   # 8: 'Pr'
                        np.float64)   # 9: 'beta'

        #**********************************************************************
        
        # convert units
        
        # 0:'T_K',
        # 1:'p_bar',
        # 2:'rho_kg_m3',
        # 3:'cp_J_Kg_K',
        # 4:'dyn_vis_N_s_m2',
        # 5:'kin_vis_m2_s',
        # 6:'k_W_m_K',
        # 7:'alpha_m2_s',
        # 8:'Pr',
        # 9:'beta'
        
        bar_2_Pa = 100000
        
        unit_converter = {
            1: lambda s: bar_2_Pa*np.float64(s)
            }

        #**********************************************************************
        
        # read the file
            
        npdata = np.genfromtxt(
            filename, 
            dtype=file_dtypes,
            names=True,
            skip_header=number_header_lines,
            skip_footer=number_footer_lines,
            delimiter=',',
            converters=unit_converter)

        #**********************************************************************
    
        # output:
        
        # 0:'T_K',
        # 1:'p_bar',
        # 2:'rho_kg_m3',
        # 3:'cp_J_Kg_K',
        # 4:'dyn_vis_N_s_m2',
        # 5:'kin_vis_m2_s',
        # 6:'k_W_m_K',
        # 7:'alpha_m2_s',
        # 8:'Pr',
        # 9:'beta'
        
        # specific_volume: dict
        # mass_density: dict
        # specific_heat: dict
        # dynamic_viscosity: dict 
        # kinematic_viscosity: dict 
        # thermal_conductivity: dict 
        # thermal_diffusivity: dict 
        # prandtl_number: dict 
        # coefficient_expansion: dict
        
        # fluid properties are nested dicts:
        # the first dict has 'phase' keys: fluid_GAS, fluid_LIQUID and fluid_SOLID
        # the second dict has other keys: key_PRESSURE, key_TEMPERATURE and key_DATAz
        
        def get_field_by_index(index_TEMPERATURE,index_PRESSURE,index_DATA):
            
            return {
                self.key_PRESSURE: npdata[names[index_PRESSURE]],
                self.key_TEMPERATURE: npdata[names[index_TEMPERATURE]],
                self.key_DATA: npdata[names[index_DATA]]
                }
        
        # 0:'T_K',
        # 1:'p_bar',
        # 2:'rho_kg_m3',
        # 3:'cp_J_Kg_K',
        # 4:'dyn_vis_N_s_m2',
        # 5:'kin_vis_m2_s',
        # 6:'k_W_m_K',
        # 7:'alpha_m2_s',
        # 8:'Pr',
        # 9:'beta'
        
        index_TEMPERATURE, index_PRESSURE = 0, 1
        
        # mass density
        
        index_DATA = 2
        
        mass_density = get_field_by_index(index_TEMPERATURE,
                                          index_PRESSURE,
                                          index_DATA)
        
        # specific heat
        
        index_DATA = 3
        
        specific_heat = get_field_by_index(index_TEMPERATURE,
                                            index_PRESSURE,
                                            index_DATA)
        
        # dynamic viscosity
        
        index_DATA = 4
        
        dynamic_viscosity = get_field_by_index(index_TEMPERATURE,
                                                index_PRESSURE,
                                                index_DATA)
        
        # kinematic viscosity
        
        index_DATA = 5
        
        kinematic_viscosity = get_field_by_index(index_TEMPERATURE,
                                                  index_PRESSURE,
                                                  index_DATA)
        
        # thermal conductivity
        
        index_DATA = 6
        
        thermal_conductivity = get_field_by_index(index_TEMPERATURE,
                                                  index_PRESSURE,
                                                  index_DATA)
        
        # thermal diffusivity
        
        index_DATA = 7
        
        thermal_diffusivity = get_field_by_index(index_TEMPERATURE,
                                                  index_PRESSURE,
                                                  index_DATA)
        
        # prandtl number
        
        index_DATA = 8
        
        prandtl_number = get_field_by_index(index_TEMPERATURE,
                                            index_PRESSURE,
                                            index_DATA)
        
        # coefficient of expansion
        
        index_DATA = 9
        
        coefficient_expansion = get_field_by_index(index_TEMPERATURE,
                                                    index_PRESSURE,
                                                    index_DATA)
        
        #**********************************************************************    
        #**********************************************************************

        # return 
        
        return (
            {phase: mass_density},
            {phase: specific_heat},
            {phase: dynamic_viscosity},
            {phase: kinematic_viscosity},
            {phase: thermal_conductivity},
            {phase: thermal_diffusivity},
            {phase: prandtl_number},
            {phase: coefficient_expansion}
            )
    
        #**********************************************************************

    #**************************************************************************
    
    def __post_init__(self, source, phase):
        
        #read from source
        
        (self.mass_density, 
         self.specific_heat,
         self.dynamic_viscosity,
         self.kinematic_viscosity,
         self.thermal_conductivity,
         self.thermal_diffusivity,
         self.prandtl_number,
         self.coefficient_expansion) = self.read(source, phase)
         
         # (self.mass_density, 
         #  self.specific_heat,
         #  self.dynamic_viscosity,
         #  self.thermal_conductivity,
         #  self.prandtl_number,
         #  self.coefficient_expansion,
         #  self.surface_tension,
         #  self.heat_vaporisation) = self.read(source)
        
        #**********************************************************************
        
    #**************************************************************************
        
#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

@dataclass
class Fluid:
    """A class for fluids."""
    
    phase: str 
    temperature: float # kelvin
    pressure: float # Pa
    
    # fluid properties are nested dicts:
    # the first dict has 'phase' keys: fluid_GAS, fluid_LIQUID and fluid_SOLID
    # the second dict has other keys: key_PRESSURE, key_TEMPERATURE and key_DATA
    
    mass_density: float = None
    specific_heat: float = None
    dynamic_viscosity: float = None
    kinematic_viscosity: float = None
    thermal_conductivity: float = None
    thermal_diffusivity: float = None
    prandtl_number: float = None
    coefficient_expansion: float = None
    
    # surface_tension: float = None
    # heat_vaporisation: float = None
    
    # # old: creation only via db
    
    # mass_density: float = field(init=False)
    # specific_heat: float = field(init=False)
    # dynamic_viscosity: float = field(init=False)
    # thermal_conductivity: float = field(init=False)
    # prandtl_number: float = field(init=False)
    # coefficient_expansion: float = field(init=False) # no phase distinction   
    # surface_tension: float = field(init=False)       # no phase distinction
    # heat_vaporisation: float = field(init=False)     # no phase distinction
    
    # kinematic_viscosity: float = field(init=False)
    
    db: InitVar[FluidDatabase] = None
    
    def __post_init__(self, db):
        
        # if a database has been provided
        
        if db != None:
        
            # check if the phase matches
            
            # initialise temperature dependent parameters
            
            from scipy.interpolate import interp1d # interp2d
            
            # get the pressure
            
            self.pressure = interp1d(
                db.mass_density[self.phase][db.key_TEMPERATURE],
                db.mass_density[self.phase][db.key_PRESSURE],
                kind='linear')(self.temperature)
        
            # interpolate data from database using temperature
            
            self.mass_density = interp1d(
                db.mass_density[self.phase][db.key_TEMPERATURE],
                db.mass_density[self.phase][db.key_DATA],
                kind='linear')(self.temperature)
            
            self.specific_heat = interp1d(
                db.specific_heat[self.phase][db.key_TEMPERATURE],
                db.specific_heat[self.phase][db.key_DATA],
                kind='linear')(self.temperature)
            
            self.dynamic_viscosity = interp1d(
                db.dynamic_viscosity[self.phase][db.key_TEMPERATURE],
                db.dynamic_viscosity[self.phase][db.key_DATA],
                kind='linear')(self.temperature)
            
            self.thermal_conductivity = interp1d(
                db.thermal_conductivity[self.phase][db.key_TEMPERATURE],
                db.thermal_conductivity[self.phase][db.key_DATA],
                kind='linear')(self.temperature)
            
            self.thermal_diffusivity = interp1d(
                db.thermal_diffusivity[self.phase][db.key_TEMPERATURE],
                db.thermal_diffusivity[self.phase][db.key_DATA],
                kind='linear')(self.temperature)
            
            self.prandtl_number = interp1d(
                db.prandtl_number[self.phase][db.key_TEMPERATURE],
                db.prandtl_number[self.phase][db.key_DATA],
                kind='linear')(self.temperature)
            
            self.coefficient_expansion = interp1d(
                db.coefficient_expansion[self.phase][db.key_TEMPERATURE],
                db.coefficient_expansion[self.phase][db.key_DATA],
                kind='linear')(self.temperature)
            
            # self.surface_tension = interp1d(
            #     db.surface_tension[self.phase][db.key_TEMPERATURE],
            #     db.surface_tension[self.phase][db.key_DATA],
            #     kind='linear')(self.temperature)
            
            # self.heat_vaporisation = interp1d(
            #     db.heat_vaporisation[self.phase][db.key_TEMPERATURE],
            #     db.heat_vaporisation[self.phase][db.key_DATA],
            #     kind='linear')(self.temperature)
            
            # initialise dependent parameters
            
            self.kinematic_viscosity = (self.dynamic_viscosity/
                                        self.mass_density)
        
#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************